package com.zztl.infiniteBand.presenter

import android.content.Context
import com.zztl.infiniteBand.base.BasePresenter
import com.zztl.infiniteBand.model.NoDataResponseBean
import com.zztl.infiniteBand.net.FilterSubscriber
import com.zztl.infiniteBand.net.RetorfitServiceManger
import com.zztl.infiniteBand.net.converter.DataConverter
import com.zztl.infiniteBand.net.requestBean.PayPwdRequest
import com.zztl.infiniteBand.ui.view.mvpview.PayPwdView


/**
 * @desc
 * @auth ${user}
 * @time 2018/8/1  10:03
 */
class PayPwdPresenter : BasePresenter<PayPwdView>() {
    private var mRequest: PayPwdRequest? = null

    fun setOrAmendPwd(pwd: String, context: Context) {
        if (null == mRequest) {
            mRequest = PayPwdRequest(pwd)
        } else {
            mRequest!!.password = pwd
        }
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService
                .setPayPwd(DataConverter.instance.toJson(mRequest!!)))
                .subscribe(object : FilterSubscriber<NoDataResponseBean>(context) {
                    override fun success(bean: NoDataResponseBean) {
                        view!!.setPayPwdSuccess()
                    }

                    override fun fail() {
                        super.fail()
                        view!!.setPayPwdFail()
                    }
                }))
    }
}
